package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.AllianceMapper;
import com.yuwubao.uav.tool.service.AllianceService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class AllianceServiceImpl implements AllianceService {

    private static final Logger logger = LogManager.getLogger(AllianceServiceImpl.class.getName());

    @Resource
    private AllianceMapper allianceMapper;

    @Override
    public void deleteAlliance(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    allianceMapper.deleteAlliance(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateAlliance(PageData pageData) throws Exception {
        try{
            allianceMapper.updateAlliance(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addAlliance(PageData pageData) throws Exception {
        try{
            allianceMapper.addAlliance(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listAlliance(PageData pageData) throws Exception {
        try{
            return allianceMapper.listAlliance(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listAllianceCount(PageData pageData) throws Exception {
        try{
            return allianceMapper.listAllianceCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    // alliance activity

    @Override
    public void deleteAllianceActivity(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    allianceMapper.deleteAllianceActivity(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateAllianceActivity(PageData pageData) throws Exception {
        try{
            allianceMapper.updateAllianceActivity(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableAllianceActivity(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    allianceMapper.disableOrEnableAllianceActivity(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addAllianceActivity(PageData pageData) throws Exception {
        try{
            allianceMapper.addAllianceActivity(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listAllianceActivity(PageData pageData) throws Exception {
        try{
            return allianceMapper.listAllianceActivity(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listAllianceActivityCount(PageData pageData) throws Exception {
        try{
            return allianceMapper.listAllianceActivityCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }


}
